window.Utils = {
    random: function (min = 0, max = 1) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    },
    randomArray: function (array) {
        return array[Math.floor(Math.random() * array.length)];
    },
    pushAll: function (src, dst) {
        src.forEach(item => {
            dst.push(item);
        });
    },
    ASyncTracker: (function () {
        var r = function ASyncTracker(name, callback) {
            var r = Object.create(ASyncTracker);
            r.tasks = 0;
            r.name = name;
            r.callback = callback;
            return r;
        }
        r.enter = function () {
            if (this.closed) return;
            this.tasks++;
        }
        r.exit = function () {
            if (this.closed) return;
            this.tasks--;
            if (this.tasks == 0) this.callback();
        }
        r.close = function (callback = false) {
            this.closed = true;
            if (callback) this.callback();
        }
        return r;
    })()
}